package com.hosever.core.model;


public class PageRequest {
	/**
	 * 总条数
	 */
	private int totalSize = 0;
	/**
	 * 每页显示的数量
	 */
	private int pageSize = 10;
	/**
	 * 总页数
	 */
	private int totalPage = 0;
	/**
	 * 当前页
	 */
	private int currentPage = 1;
	/**
	 * 开始查询的数。
	 */
	private int start = 0; 
	/**
	 * 结束查询的数。
	 */
	private int end = 0; 
	
	public PageRequest(){
		super();
	}
	
	public PageRequest(int totalSize){
		this.totalSize = totalSize;
		this.pageSize = 10;
		setCurrentPage(1);
	}
	public PageRequest(int totalSize,int pageSize){
		this.totalSize = totalSize;
		if(pageSize == 0){
			this.pageSize = 10;
		}else{
			this.pageSize = pageSize;
		}
		setCurrentPage(1);
	}

	/**
	 * 获取总条数
	 * @return
	 */
	public int getTotalSize() {
		return totalSize;
	}
	
	/**
	 * 设置总条数
	 * @param totalSize
	 */
	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
		setTotalPage(((this.totalSize-1)/pageSize)+1);
	}
	
	/**
	 * 获取每页显示条数
	 * @return
	 */
	public int getPageSize() {
		return pageSize;
	}
	
	/**
	 * 设置每页显示条数
	 * @param pageSize
	 */
	public void setPageSize(int pageSize) {
		this.totalPage = pageSize;
	}
	
	/**
	 * 获取总页数
	 * @return
	 */
	public int getTotalPage() {
		return totalPage;
	}
	
	/**
	 * 获取当前页
	 * @return
	 */
	public int getCurrentPage() {
		return currentPage;
	}
	
	/**
	 * 设计当前页时，计算stare
	 * @param currentPage
	 */
	public void setCurrentPage(int currentPage) {
		if(currentPage<0){
			this.currentPage = 1;
		}else{
			this.currentPage = currentPage;
		}
		
		//计算查询，每页10条为例，第一页0,9，第二页10,19
		setStart(pageSize*(currentPage-1));
		setEnd(pageSize*currentPage-1);
		
	}
	
	/**
	 * 从第start开始查询
	 * @return
	 */
	public int getStart() {
		return start;
	}
	
	/**
	 * 设置从第start开始查询
	 * @param start
	 */
	public void setStart(int start) {
		this.start = start;
	}
	
	/**
	 * 获取查询到第end条
	 * @return
	 */
	public int getEnd() {
		return end;
	}
	
	/**
	 * 设置查询到第end条
	 */
	public void setEnd(int end) {
		this.end = end;
	}

	/**
	 * 设置 总页数
	 * @param totalPage the totalPage to set
	 */
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
}
